Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

362 lines
9.3 KiB

  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!-- ExtFunctions.xsl -->
  3. <xsl:stylesheet
  4. version="1.0"
  5. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  6. xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  7. xmlns:ssr="http://microsoft.com/sce/ssr"
  8. >
  9. <!-- so that we can use those extension function already written -->
  10. <xsl:output method="text" indent="no"/>
  11. <msxsl:script language="JScript" implements-prefix="ssr">
  12. <!-- do not analyze xml syntax -->
  13. <![CDATA[
  14. //
  15. // This function returns the value of the attribute given the node
  16. //
  17. function AttribValue(NodeList, AttriName)
  18. {
  19. var Node = NodeList.nextNode();
  20. return Node.attributes.getNamedItem(AttriName).text;
  21. }
  22. //
  23. // some string manipulation functions
  24. //
  25. //
  26. // This function returns the value of the named token (TokenName)
  27. // which is encoded into string in the format of Name=Value delimited
  28. // by the DelimiterChar
  29. //
  30. function GetValue(TokenList, TokenName, DelimiterChar)
  31. {
  32. var index = TokenList.lastIndexOf(TokenName);
  33. if (index != -1)
  34. {
  35. var comma = index + TokenName.length + 1;
  36. while (comma < TokenList.length)
  37. {
  38. if (TokenList.charAt(comma) == DelimiterChar)
  39. break;
  40. comma++;
  41. }
  42. if (comma == TokenList.length)
  43. {
  44. return TokenList.substr(index + TokenName.length + 1);
  45. }
  46. else
  47. {
  48. return TokenList.substring(index + TokenName.length + 1, comma);
  49. }
  50. }
  51. return "";
  52. }
  53. //
  54. // Given a list of tokens (TokenList) which are packed together into a string
  55. // separated by the given delimiter (DelimiterChar), this function returns the
  56. // index for the next token from the StartIndex
  57. //
  58. function GetNextIndex(TokenList, StartIndex, DelimiterChar)
  59. {
  60. var NextIndex = StartIndex;
  61. while (NextIndex < TokenList.length)
  62. {
  63. if (TokenList.charAt(NextIndex) == DelimiterChar)
  64. break;
  65. NextIndex++;
  66. }
  67. return NextIndex;
  68. }
  69. //
  70. // Given a list of tokens (TokenList) which are packed together into a string
  71. // separated by the given delimiter (DelimiterChar), this function returns "1"
  72. // if the given token (Token) is present in the list and "0" otherwise
  73. //
  74. function IsTokenPresent(TokenList, Token, DelimiterChar)
  75. {
  76. var index = TokenList.indexOf(Token);
  77. if (index != -1)
  78. {
  79. if ( (index == 0 || TokenList.charAt(index-1) == DelimiterChar) &&
  80. (index + Token.length >= TokenList.length || TokenList.charAt(index + Token.length) == DelimiterChar) )
  81. return "1";
  82. }
  83. return "0";
  84. }
  85. //
  86. // This function collects all attributes of the given name (AttribName) of child elements
  87. // (whose name is SubNodeName) immediately under NodeList and pack the values together into
  88. // a string separated by the given delimiter (DelimiterChar)
  89. //
  90. function GetAllSubNodeAttribute(NodeList, SubNodeName, AttribName, DelimiterChar)
  91. {
  92. try
  93. {
  94. var node = NodeList.nextNode();
  95. var SubNodeColl = node.selectNodes(SubNodeName);
  96. var Result = "";
  97. var count = SubNodeColl.length;
  98. var SubNode;
  99. var i;
  100. for (i = 0; i < count; i++)
  101. {
  102. SubNode = SubNodeColl.nextNode();
  103. Result += SubNode.attributes.getNamedItem(AttribName).text + DelimiterChar;
  104. }
  105. return Result;
  106. }
  107. catch (e)
  108. {
  109. return "";
  110. }
  111. }
  112. //
  113. // This function collects attributes of NT services of the given name and return a string
  114. // in the form of "StartMode=xxx,Started=true/false" format
  115. //
  116. function GetServiceInfo(ServiceName)
  117. {
  118. try
  119. {
  120. var obj = new ActiveXObject("wbemscripting.swbemlocator");
  121. var ns = obj.connectserver(".","root\\cimv2");
  122. var Path = "win32_service.name='" + ServiceName + "'";
  123. var Svc = ns.get(Path);
  124. return "StartMode=" + ((Svc.StartMode == "Auto") ? "Automatic" : Svc.StartMode) + ",Started=" + Svc.Started;
  125. }
  126. catch (e)
  127. {
  128. return "";
  129. }
  130. }
  131. //
  132. // the following two functions are to read/write/delete registry keys
  133. //
  134. var sh = new ActiveXObject("WScript.Shell");
  135. function RegRead(KeyPath)
  136. {
  137. var Value = "";
  138. try
  139. {
  140. Value = sh.RegRead(KeyPath);
  141. }
  142. catch (e)
  143. {
  144. }
  145. return Value;
  146. }
  147. //
  148. // KeyType can be: REG_SZ, REG_EXPAND_SZ, REG_BINARY, REG_DWORD, REG_MULTI_SZ
  149. //
  150. function RegWrite(KeyPath, KeyValue, KeyType)
  151. {
  152. try
  153. {
  154. sh.RegWrite(KeyPath, KeyValue, KeyType);
  155. return 1;
  156. }
  157. catch (e)
  158. {
  159. return 0;
  160. }
  161. }
  162. //
  163. // KeyType can be: REG_SZ, REG_EXPAND_SZ, REG_BINARY, REG_DWORD, REG_MULTI_SZ
  164. //
  165. function RegDelete(KeyPath)
  166. {
  167. try
  168. {
  169. sh.RegDelete(KeyPath);
  170. return 1;
  171. }
  172. catch (e)
  173. {
  174. return 0;
  175. }
  176. }
  177. //
  178. // Folder traversing functions
  179. //
  180. var FileSysObj = new ActiveXObject("Scripting.FileSystemObject");
  181. // This function will query all sub-folders residing under the given FolderPath
  182. // The result will be packed together with with the given delimiter char.
  183. //
  184. function CreateSubFolderList (FolderPath, Delimiter)
  185. {
  186. var Folder = FileSysObj.GetFolder(FolderPath);
  187. var SubDirEnum = new Enumerator(Folder.SubFolders);
  188. var DelFolderList = "";
  189. for (SubDirEnum.moveFirst(); !SubDirEnum.atEnd(); SubDirEnum.moveNext())
  190. {
  191. var Folder = SubDirEnum.item();
  192. DelFolderList += Folder.Path + Delimiter;
  193. }
  194. return DelFolderList;
  195. }
  196. //
  197. // Query those files which resides under the given FolderPath with the given
  198. // attribute Attrib (ReadOnly or ReadWrite).
  199. // Since we can't pass arrays inside xsl, we opt to pack the array
  200. // into a string delimited by the given Delimiter.
  201. // Note: it doesn't iterate to the sub-folders!
  202. //
  203. function CreateFileList (FolderPath, Delimiter, Attrib)
  204. {
  205. var Folder = FileSysObj.GetFolder(FolderPath);
  206. var FileEnum = new Enumerator(Folder.Files);
  207. var DelFileList = "";
  208. for (FileEnum.moveFirst(); !FileEnum.atEnd(); FileEnum.moveNext())
  209. {
  210. var File = FileEnum.item();
  211. if ( (Attrib == 0) ||
  212. (Attrib == "ReadOnly") && (File.attributes & 1) ||
  213. (Attrib == "ReadWrite") && (File.attributes & 1) == 0)
  214. {
  215. DelFileList += File.Path + Delimiter;
  216. }
  217. }
  218. return DelFileList;
  219. }
  220. //
  221. // Query the attribute of the file
  222. // If the file doesn't exist, it returns an empty string
  223. //
  224. function GetFileAttribute (FilePath)
  225. {
  226. var attr = "";
  227. try
  228. {
  229. var File = FileSysObj.GetFile(FilePath);
  230. if ((File.attributes & 1))
  231. {
  232. attr = "ReadOnly";
  233. }
  234. else if ((File.attributes & 1) == 0)
  235. {
  236. attr = "ReadWrite";
  237. }
  238. }
  239. catch (e)
  240. {
  241. attr = "";
  242. }
  243. return attr;
  244. }
  245. //
  246. // Query the attribute of the file
  247. // If the file doesn't exist, it returns an empty string
  248. //
  249. function GetFileLocation (ActionName, FileName)
  250. {
  251. var Path;
  252. try
  253. {
  254. var DirPath = sh.ExpandEnvironmentStrings("%WinDir%\\Security\\SSR");
  255. var UpperActionName = ActionName.toUpperCase();
  256. if (UpperActionName == "CONFIGURE")
  257. {
  258. Path = DirPath + "\\ConfigureFiles\\" + FileName;
  259. }
  260. else if (UpperActionName == "ROLLBACK")
  261. {
  262. Path = DirPath + "\\RollbackFiles\\" + FileName;
  263. }
  264. else if (UpperActionName == "REPORT")
  265. {
  266. Path = DirPath + "\\ReportFiles\\" + FileName;
  267. }
  268. else
  269. {
  270. Path = "Action Not Recognized";
  271. }
  272. }
  273. catch (e)
  274. {
  275. Path = "Exception occurred";
  276. }
  277. return Path;
  278. }
  279. ]]>
  280. </msxsl:script>
  281. <xsl:template match="SSRCopyRight">
  282. ' This VB script file is created by Microsoft Secure Server Roles� XSL transformation
  283. ' from the XML file created by Microsoft Secure Server Roles� wizard.
  284. ' <xsl:value-of select="."/>
  285. On Error Resume Next
  286. </xsl:template>
  287. <xsl:template match="RevHistory">
  288. </xsl:template>
  289. </xsl:stylesheet>